﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using facebook;

namespace Veracruz.Facebook.Data
{
    public static class EmailAssociation  // TODO : Change access modifier to internal
    {
        #region consts

        public const string Name = "email";
        public const string UserId = "uid";
        public const string User = "user";
        public const string GetEmail = "select _data from app.email where uid={0}";
        public const string GetFriendsEmail = "select uid, _data from app.email where uid in (select uid1 from friend where uid2 ={0})";

        #endregion
        #region methods

        public static string GetEmailQuery(long uid)
        {
            return string.Format(GetEmail, uid);
        }
        public static string GetEmailsQuery(long uid)
        {
            return string.Format(GetFriendsEmail, uid);
        }
        internal static void Reset(Session session)
        {
            // email uid <---> user unique  user, unique  
            API l_api = FacebookHelper.CreateAPI(session);
            l_api.data.undefineAssociation(Name);

            //users uid ---> application_id unique  
            //            integer  assoc_type  Type of this association: 
            //1: one-way association, where reverse lookup is not needed; 
            //2: two-way symmetric association, where a backward association (B to A) is always created when a forward association (A to B) is created. 
            //3: two-way asymmetric association, where a backward association (B to A) has different meaning than a forward association (A to B).  
            //l_api.data.defineAssociation(Name, );
            facebook.Schema.assoc_object_type l_obj1 = new facebook.Schema.assoc_object_type();
            l_obj1.alias = UserId;
            l_obj1.object_type = string.Empty;
            l_obj1.unique = true;
            facebook.Schema.assoc_object_type l_obj2 = new facebook.Schema.assoc_object_type();
            l_obj2.alias = User;
            l_obj2.object_type = UserObjectType.Name;
            l_obj2.unique = true;
            l_api.data.defineAssociation(Name, 2, l_obj1, l_obj2, null);
        }

        #endregion
        #region queries

        public static class Queries
        {
            
        }

        #endregion
    }
}
